<?php
/**
 * Created by PhpStorm.
 * User: chenjz
 * Date: 2017/11/22
 * Time: 13:26
 */
class ResponseUtil {
    public $code; // 暂时不用
    public $errMsg;
    public $data;
    public function __construct($code = 0, $errMsg = '', $data = '') {
        $this->code = $code;
        $this->errMsg = $errMsg;
        $this->data = $data;
    }

    public function success($data) {
        $this->data = $data;
        echo $this->output();//json_encode($data)
    }

    public function fail($errMsg) {
        $this->errMsg = $errMsg;
        exit($this->output());
    }

    private function output() {
        return json_encode($this, JSON_UNESCAPED_UNICODE);
      //  return json_encode($this->data );
    }
}